#!/bin/bash
nmcli  connection  show
# 删除eth0和eth1的配置(根据实际网卡名改)
nmcli  connection  delete  eth0
nmcli  connection  delete  eth1
# 创建bond0名(根据实际bond名改)
nmcli  connection  add  type  bond  ifname  bond0  con-name  bond0  mode  active-backup  miimon  100
# 加入bond中
nmcli  connection  add  type  bond-slave  ifname  eth0  con-name  bond0-eth0  master  bond0
nmcli  connection  add  type  bond-slave  ifname  eth1  con-name  bond0-eth1  master  bond0
# 命令设置bond静态IP(也可以手动改文件设置)(根据实际设置)
nmcli  connection  modify  bond0  ipv4.method  manual  ipv4.addresses  192.168.100.2/24 ipv4.gateway 192.168.100.254  autoconnect  yes
# 启动bond
nmcli  connection  up  bond0

# 设置默认网卡配置文件
mkdir  -p  /etc/network/
touch  /etc/network/default_gw
if  grep  -qF  "interface=bond0"  /etc/network/default_gw ; then
    echo  "/etc/network/default_gw文件包含interface=bond0"
else
    echo  "interface=bond0" | tee  -a  /etc/network/default_gw
fi

ip  a

echo  "请手动检查IP是否通网关"